/*
 * TimeDate.h
 *
 *  Created on: 20.09.2011
 *      Author: windows97
 */

#ifndef TIMEDATE_H_
#define TIMEDATE_H_

typedef struct _T_Time
{
  uint8_t  Hour;
  uint8_t  Minute;
  uint8_t  Second;
} T_Time;

typedef struct _T_Date
{
  uint16_t  Day:5;
  uint16_t  Month:4;
  uint16_t  Year:7;
  uint16_t  WeekDay:3;
} T_Date;

typedef struct _T_TimeDate
{
  T_Time  Time;
  T_Date  Date;
}T_TimeDate;

typedef enum _T_WeekDay
{
  Unknown   = 0,
  Monday    = 1,
  Tuesday   = 2,
  Wednesday = 3,
  Thursday  = 4,
  Friday    = 5,
  Saturday  = 6,
  Sunday    = 7
} T_WeekDay;

typedef enum
{
  SecondChange,
  MinuteChange,
  HourChange,
  DayChange,
  MonthChange,
  YearChange, /* for happy new year??? */
  TimeSetChange,
  NotSet
}T_TimeChangeNotifyReason;

typedef enum _T_Month
{
  January,
  February,
  March,
  April,
  May,
  June,
  July,
  August,
  September,
  October,
  November,
  December
} T_Month;

typedef void (*T_TimeChangeNotify) (void);

/* max values */
#define TIME_MIN_MAX    ((uint8_t) (60U))
#define TIME_SEC_MAX    ((uint8_t) (60U))
#define TIME_HOUR_MAX   ((uint8_t) (24U))
#define DATE_DAY_MAX    ((uint8_t) (32U))
#define DATE_MON_MAX    ((uint8_t) (13U))
#define DATE_WDAY_MAX   ((uint8_t) (8U))
#define DATE_YEAR_MAX   ((uint8_t) (100U)) /* just for plausibility checking of the stored year */
/* min values */

#define DATE_MON_MIN    ((uint8_t) (1U))
#define DATE_YEAR_MIN   ((uint16_t)(11U))
/* other */
#define DATE_YEAR_BASE  ((uint16_t) (2000U))

void calculate_time( T_Time* iTime1, int subtract, T_Time* iTime2);
void TidGetTimeDate( T_TimeDate* iTimeDate );
void TidSetTimeDate( T_TimeDate* iTimeDate );
void TidGetTime( T_Time* iTime );
void TidGetDate( T_Date* iDate );
void TidUpdateSecond( void );
void TidRegisterNotification( T_TimeChangeNotify iNotifyFunction, T_TimeChangeNotifyReason iReason );
void TidGetStoredTimeDate( void );
void TidInit(void);
void TidCyclic( void );

#endif /* TIMEDATE_H_ */
